#include <graphics/vertexbuffer.h>
#include <graphics/utils.h>
#include <graphics/vertexarray.h>
#include <assert.h>


namespace yam3d
{
namespace graphics
{

VertexBuffer::VertexBuffer()
{
}


VertexBuffer::~VertexBuffer()
{

    for( HashType::iterator it = m_vertexArrays.begin(); it != m_vertexArrays.end(); ++it )
    {
        delete *it;
    }
}


void VertexBuffer::addVertexArray( const char* const name, VertexArray* va )
{
    m_vertexArrays[name] = va;
}

void VertexBuffer::setVertexArrays(QGLShaderProgram* program)
{
    for( HashType::iterator it = m_vertexArrays.begin(); it != m_vertexArrays.end(); ++it )
    {
        assert( *it != 0 );
        program->enableAttributeArray(it.key());
        checkGlError("QGLShaderProgram::enableAttributeArray(name=%s)", it.key() );
        it.value()->setAttributeArray(program, it.key());
    }
}


}
}

